﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using NXDO.WebAPI.Controllers;
using System;
using System.IO;
using TDM.DbData.DataEntity;
using TDM.WebBase;
using TDM.WebBiz.TestData;

namespace TDM.WebSvr.Controllers.TestData
{
    [AllowAnonymous]
    public class DataExportController : ApiDbEntityController<DataExport, long>
    {

        protected override string GetPkName()
        {
            return "ExportID";
        }

        protected override string GetTableName()
        {
            return "DataExport";
        }


        public override bool Delete(long pkValue)
        {
            var dataExport = DataExportHelper.Get(pkValue);
            if (dataExport == null) throw new Exception("未找到需要删除的数据");
            try
            {
                string basePath = BasePathHelper.GetDataExportPath();
                string fullpath = Path.Combine(basePath, dataExport.FilePath);
                if (System.IO.File.Exists(fullpath)) System.IO.File.Delete(fullpath);
            }
            catch (Exception)
            {
            }
            return base.Delete(pkValue);
        }

        /// <summary>
        /// 创建导出数据包
        /// </summary>
        [HttpGet]
        public void CreateExportPack()
        {
            WebBiz.TestData.DataExportHelper.ExeCreateExportData();
        }
    }
}
